// axios
//   .post(
//     "http://openapi.music.163.com/openapi/music/basic/recommend/songlist/get/v2?appId=a301010000000000aadb4e5a28b45a67&bizContent=%7B%22limit%22%3A100%7D&signType=RSA_SHA256&accessToken=x46c13d33a898ad1d257c5009a1daadfced5a1160176c2309y&device=%7B%22deviceType%22%3A%22andrwear%22%2C%22os%22%3A%22andrwear%22%2C%22appVer%22%3A%220.1%22%2C%22channel%22%3A%22hm%22%2C%22model%22%3A%22kys%22%2C%22deviceId%22%3A%22321%22%2C%22brand%22%3A%22hm%22%2C%22osVer%22%3A%228.1.0%22%7D&timestamp=1615446390779"
//   )
//   .then((data) => {
//     console.log("data", data);
//   });
import router from "@/router";
// import ElementUI from "element-ui";
//这是拦截器
import axios from "axios";
//创建一个单例(实例)
const instance = axios.create({
  baseURL: "/api",
  timeout: 4000,
});

//拦截器-请求拦截
instance.interceptors.request.use(
  (config) => {
    //部分接口需要拿到token
    let token = localStorage.getItem("usertoken");
    if (token) {
      config.headers["authorization"] = token;
    }

    return config;
  },
  (err) => {
    return Promise.reject(err);
  }
);

//拦截器-响应拦截
instance.interceptors.response.use(
  (res) => {
    // console.log(res.data);
    if(res?.data?.code==606){
      // ElementUI.Message({
      //   message:res?.data?.msg,
      //   type:"error"
      // })
      //清空token再
      //跳转到登录页面
      localStorage.removeItem("usertoken")
      localStorage.removeItem("userinfo")
      router.push('/managelogin')
    }
    return res;
  },
  (err) => {
    console.log("err", err);
    let msg = "服务器出错啦";
    return Promise.reject(msg);
  }
);

//整体导出
export default instance;
